<template>
	<view class="home">
		<view class="home-box">
			<uv-form labelPosition="top" :model="withdrawaletupS" :rules="rules" ref="form" labelWidth="88">
				<uv-form-item label="收货人" prop="realName" borderBottom>
					<uv-input v-model="withdrawaletupS.realName" border="none" placeholder="请输入收货人姓名或昵称">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="联系电话" prop="phone" borderBottom>
					<uv-input v-model="withdrawaletupS.phone" border="none" placeholder="请输入您的联系方式">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="省市区" prop="province" borderBottom>
					<uv-input v-model="withdrawaletupS.province" border="none" placeholder="请选择省市区">
					</uv-input>
				</uv-form-item>
				<uv-form-item label="详细地址" prop="address" borderBottom>
					<uv-input v-model="withdrawaletupS.address" border="none" placeholder="请输入您的详细地址">
					</uv-input>
				</uv-form-item>
			</uv-form>
			<button type="default" class="top_btn" @click="submit">确认保存</button>
		</view>
	</view>
</template>

<script>
	import apiMoen from '../../../../utils/config.js';
	export default {
		data() {
			return {
				fileList1: [],
				withdrawaletupS: {
					realName: '',
					phone: '',
					province: '',
					address: '',
				},
				rules: {
					realName: [{
						type: 'string',
						required: true,
						message: '请输入真实姓名',
						trigger: ['blur', 'change']
					}],
					phone: [{
						type: 'string',
						required: true,
						message: '请输入联系电话',
						trigger: ['blur', 'change']
					}, {
						pattern: /^1[3-9]\d{9}$/,
						// 正则检验前先将值转为字符串
						transform(value) {
							console.log(value, '111111111111111111111')
							return String(value);
						},
						message: '手机号格式错误'
					}],
					province: [{
						type: 'string',
						required: true,
						message: '请输入地区',
						trigger: ['blur', 'change']
					}],
					address: [{
						type: 'string',
						required: true,
						message: '请输入详细地址',
						trigger: ['blur', 'change']
					}],
				},
			}
		},
		mounted() {
			uni.showToast({
				icon: 'none',
				title: '请填写收货地址',
				duration: 2000,
			});
		},
		methods: {
			// 参与任务列表
			submit() {
				this.$refs.form.validate().then(res => {
					this.$request('signin.signinEditMyInfo', {
						sysOrgCode: uni.getStorageSync('sysOrgCode'),
						memberId: uni.getStorageSync('id'),
						address: this.withdrawaletupS.address,
						area: this.withdrawaletupS.province,
						realName: this.withdrawaletupS.realName,
						phone: this.withdrawaletupS.phone
					}).then(res => {
						if (res.code == 200) {
							uni.showToast({
								icon: 'none',
								title: '收货地址保存成功',
								duration: 2000,
							});
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages/home/bonus/mall/mall'
								}, 10000)
							})
						}
					})
				}).catch(errors => {
					uni.showToast({
						icon: 'error',
						title: '输入错误请重新输入'
					})
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	@import 'index.scss';

	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
</style>